//
//  ViewController.m
//  XIB自动布局
//
//  Created by 周成龙 on 16/11/3.
//  Copyright © 2016年 ZCL. All rights reserved.
//

#import "ViewController.h"

#import "StatusModel.h"
#import "UserModel.h"
#import <MJExtension.h>

#import "StatusCell.h"

@interface ViewController ()

@property (nonatomic, copy)NSArray *contentArray;

@end

@implementation ViewController

- (NSArray *)contentArray {
    if (_contentArray == nil) {
        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:0];
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"status.plist" ofType:nil];
        
        NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path];
        
        NSArray *statuses = dict[@"statuses"];
        
        NSLog(@"status=%@", statuses);
        
        for (int i =0; i < statuses.count; i ++) {
            
            NSDictionary *dcit = statuses[i];
            
            StatusModel *model = [StatusModel mj_objectWithKeyValues:dcit];
            
            [StatusModel mj_setupObjectClassInArray:^NSDictionary *{
                return @{
                         @"pic_urls":@"PicModel"
                         };
            }];
            
            [arr addObject:model];
        }
        _contentArray = arr;
    }
    return _contentArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 300;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.contentArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *ID = @"cell";
    
    StatusCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    
    if (!cell) {
        //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:ID];
        
        cell = [[[NSBundle mainBundle] loadNibNamed:@"StatusCell" owner:nil options:nil] lastObject];
    }
    
    StatusModel *model = self.contentArray[indexPath.row];
    cell.model = model;
    
    return cell;
}


@end
